import unittest
from datetime import time
from hurryoff.core.filters import transferFilter
from hurryoff.core.router import PathPart

class FilterTests(unittest.TestCase):

    def test_transferTimeFilterCorrect(self):
        route = [PathPart("point1", "point2", time(10, 10), time(10, 30), None)]
        self.assertEqual(transferFilter(route), route)

        route = [PathPart("point1", "point2", time(10, 10), time(10, 30), None), \
                 PathPart("point1", "point2", time(10, 50), time(14, 31), None)]
        self.assertEqual(transferFilter(route), route)

        route = [PathPart("point1", "point2", time(10, 10), time(10, 30), None), \
                 PathPart("point1", "point2", time(10, 50), time(14, 31), None), \
                 PathPart("point1", "point2", time(0, 10), time(8, 31), None)]
        self.assertEqual(transferFilter(route), route)

        route = [PathPart("point1", "point2", time(10, 10), time(10, 30), None), \
                 PathPart("point1", "point2", time(13, 20), time(14, 31), None)]
        self.assertEqual(transferFilter(route, maxDelay=3*60), route)

    def test_transferTimeFilterIncorrect(self):
        route = [PathPart("point1", "point2", time(10, 10), time(10, 30), None), \
                 PathPart("point1", "point2", time(23, 50), time(0, 31), None)]
        self.assertIsNone(transferFilter(route))

        route = [PathPart("point1", "point2", time(10, 10), time(10, 30), None), \
                 PathPart("point1", "point2", time(10, 50), time(14, 31), None), \
                 PathPart("point1", "point2", time(3, 10), time(8, 31), None)]
        self.assertIsNone(transferFilter(route))

        route = [PathPart("point1", "point2", time(10, 10), time(10, 30), None), \
                 PathPart("point1", "point2", time(10, 50), time(14, 31), None), \
                 PathPart("point1", "point2", time(17, 32), time(8, 31), None)]
        self.assertIsNone(transferFilter(route, maxDelay=3*60))